package com.meta.platform.contract.core.repository.impl;

import com.meta.framework.common.utils.SecurityUtils;
import com.meta.platform.contract.core.mapper.ContractFundRecordMapper;
import com.meta.platform.contract.domain.aggr.ContractFundRecordDo;
import com.meta.platform.contract.domain.tunnel.db.ContractFundRecordRepository;
import com.meta.platform.contract.intf.entity.ContractFundRecord;
import com.meta.platform.contract.intf.ro.ContractFundRecordRo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * 合同回款记录
 *
 * @Title: ContractFundRecordRepositoryImpl
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2020-12-08 15:53:39
 * @Version: v2.0
 */
@Service
public class ContractFundRecordRepositoryImpl implements ContractFundRecordRepository {

    @Resource
    private ContractFundRecordMapper contractFundRecordMapper;

    /**
     * insert contractFundRecord info
     *
     * @param contractFundRecord:
     * @return void
     * @method insertContractFundRecord
     * @author M.simple
     * @date 2020-12-08 15:53:39
     */
    @Override
    public void insertContractFundRecord(ContractFundRecordDo contractFundRecord) {
        contractFundRecord.setCreateBy(SecurityUtils.getUserId());
        contractFundRecord.setUpdateBy(SecurityUtils.getUserId());
        contractFundRecordMapper.insertContractFundRecord(contractFundRecord);
    }

    /**
     * batch insert contractFundRecord info
     *
     * @param contractFundRecords:
     * @return void
     * @method insertContractFundRecord
     * @author M.simple
     * @date 2020-12-08 15:53:39
     */
    @Override
    public void batchInsertContractFundRecord(List<ContractFundRecord> contractFundRecords) {
        contractFundRecordMapper.batchInsertContractFundRecord(contractFundRecords);
    }

    /**
     * update contractFundRecord info
     *
     * @param contractFundRecord:
     * @return int
     * @method updateContractFundRecord
     * @author M.simple
     * @date 2020-12-08 15:53:39
     */
    @Override
    public int updateContractFundRecord(ContractFundRecord contractFundRecord) {
        contractFundRecord.setUpdateBy(SecurityUtils.getUserId());
        return contractFundRecordMapper.updateContractFundRecord(contractFundRecord);
    }

    /**
     * update contractFundRecord info by Pk
     *
     * @param contractFundRecord:
     * @return int
     * @method updateContractFundRecordByPk
     * @author M.simple
     * @date 2020-12-08 15:53:39
     */
    @Override
    public int updateContractFundRecordByPk(ContractFundRecord contractFundRecord) {
        contractFundRecord.setUpdateBy(SecurityUtils.getUserId());
        return contractFundRecordMapper.updateContractFundRecordByPk(contractFundRecord);
    }

    /**
     * list contractFundRecord info
     *
     * @param contractFundRecord:
     * @return List<ContractFundRecord>
     * @method listContractFundRecord
     * @author M.simple
     * @date 2020-12-08 15:53:39
     */
    @Override
    public List<ContractFundRecord> listContractFundRecord(ContractFundRecordRo contractFundRecord) {
        return contractFundRecordMapper.listContractFundRecord(contractFundRecord);
    }

    @Override
    public List<ContractFundRecordDo> listContractFundRecordDo(ContractFundRecordRo contractFundRecord) {
        return ContractFundRecordDo.of(contractFundRecordMapper.listContractFundRecord(contractFundRecord));
    }

    @Override
    public ContractFundRecordDo getById(Long id) {
        if (id == null){
            return null;
        }
        ContractFundRecordRo ro = new ContractFundRecordRo();
        ro.setId(id);
        List<ContractFundRecord> res = contractFundRecordMapper.listContractFundRecord(ro);
        if (CollectionUtils.isEmpty(res)){
            return null;
        }
        return ContractFundRecordDo.of(res.get(0));
    }
}
